import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:grint/bloc/auth_cubit.dart';
import 'package:grint/bloc/chat_cubit.dart';
import 'package:grint/bloc/comment_cubit.dart';
import 'package:grint/bloc/content_curator_cubit.dart';
import 'package:grint/bloc/follow_cubit.dart';
import 'router/app_router.dart';
import 'utils/time_reminder_service.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  TimeReminderService().startTimeCheck();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(create: (context) => AuthCubit()),
        BlocProvider(create: (context) => ContentCuratorCubit()),
        BlocProvider(create: (context) => CommentCubit()),
        BlocProvider(create: (context) => FollowCubit()),
        BlocProvider(create: (context) => ChatCubit()),
      ],
      child: ScreenUtilInit(
        designSize: const Size(375, 805),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (context, child) {
          return MaterialApp.router(
            title: 'Grint',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
              fontFamily: 'MiSans Latin',
            ),
            routerConfig: AppRouter.router,
            builder: FlutterSmartDialog.init(
              builder: (context, child) {
                return MediaQuery(
                  data: MediaQuery.of(
                    context,
                  ).copyWith(textScaler: TextScaler.linear(1.0)),
                  child: child!,
                );
              },
            ),
          );
        },
      ),
    );
  }
}
